package web.controller.common;

import common.consts.Consts;
import common.consts.ResponseStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.ServiceResponse;
import web.Routes;
import web.controller.Base;
import web.utils.RequestHolder;

import javax.servlet.ServletContext;

/**
 * Created by Ace Yin on 2015/5/29 0029.
 * Public API listing.
 */
@RestController
@RequestMapping(Routes.Common.APIS)
public class Apis extends Base {

    public ServiceResponse get() {
        ServiceResponse response = ServiceResponse.success();
        ServletContext context = RequestHolder.RAW_REQUEST.get().getServletContext();
        Object mappings = context.getAttribute(Consts.SPRING_MVC_MAPPING_KEY);
        if (mappings != null) {
            return ServiceResponse.success().with("mappings", mappings);
        } else {
            response.setStatus(ResponseStatus.FAIL.code);
        }
        return response;
    }
}
